package com.yt.controller;

import org.springframework.stereotype.Component;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Classname RhFilter
 * @Description
 * @Date 2021/11/9 15:19
 * @Create by 杨涛
 */
@Component
//@WebFilter("/json/*")
public class RhFilter extends HttpFilter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req=(HttpServletRequest)request;
        String url=req.getRequestURI();
        System.out.println(url);
        if(url.startsWith("/fmt/")) {
            chain.doFilter(req, response);
            return;
        }
        HttpServletResponse resp=(HttpServletResponse)response;
        resp.setHeader("Access-Control-Allow-Origin","*");
        resp.setHeader("Access-Control-Allow-Methods","GET,POST");
        resp.setContentType("application/json;charset=utf8");
        chain.doFilter(request,response);
    }
}
